﻿@model LynxWiki.ViewModels.TopicVersionViewData

@using LynxWiki.ViewModels;

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutTopic.cshtml";
}

@Html.Partial("_TopicDisplayName", new TopicDisplayName { DisplayName = Model.TopicName })
@if(!Model.AllowUpdate) {
    <p>@ViewBag.User: does not have write access to this topic</p>
}
@if (Model.TopicLock) {
    <p>Topic is readonly.</p>
}
@using (Html.BeginForm("EditTopic", "WikiTopic", FormMethod.Post, new { id = "frmEditTopic" })) {
   
<div>@Html.TextAreaFor(model => model.Topic.WikiText, new { @class = "editBody" })
    <div id="wikiMarkupGuide">
        <p><b>Brief Markup Guide</b></p>
        <span>*bold*</span><br />
        <span>_italics_</span><br />
        <span>+underline+</span><br /><br />
        <span>! Heading 1</span><br />
        <span>!! Heading 2</span><br /><br />
        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Bullet List 1 (8 spcs)</span><br />
        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Bullet 2 (16 spcs)</span><br />
        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. Number List 1 (8 spcs)</span><br />
        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. Number 2 (16 spcs)</span><br /><br />
        <span>WikiPageLink</span><br />
        <span>http://www.example.com</span><br />
        <span>"Relabelled Link":http://www.example.com</span><br /><br />
        <span>""Escape Formatting""</span><br /><br />
        <span>||Table R1C1|| R1C2||</span><br />
        <span>|| R2C1 || R2C2 ||</span><br /><br />
        <span><a href="@Url.RouteUrl("PageDisplay", new { action = "Page", controller = "WikiTopic", pagePath = "/WikiRoot/WikiDir/FormattingRules"  })" target="_blank">Formatting Rules Reference</a></span><br />
    </div></div>
    <div><a id="displayMarkupGuide" href="#">Brief Markup Guide</a></div>
    @Html.LabelFor(model => model.Tags)<div id="ErrorMsgDiv" ></div>
    @Html.TextAreaFor(model => model.Tags)
    if (Model.AllowUpdate == true && Model.TopicLock == false) {
        if (Convert.ToBoolean(ViewBag.CaptchaSetting)) {
            <br /> @Html.LabelFor(model => model.CaptchaInput)<img alt="Captcha" src="@Url.Action("CaptchaImage")" />
        <div class="editor-field">
        @Html.EditorFor(model => model.CaptchaInput) 
        @Html.ValidationMessageFor(model => model.CaptchaInput)</div>
        }
        <input type="submit" name="btnNewVersion" id="btnNewVersion" value="New Version" />
        <input type="submit" name="btnMinorUpdate" id="btnMinorUpdate" value="Minor Update" />
        <input type="submit" name="btnPreview" id="btnPreview" value="Preview" /><br />
    }
    <div><a id="slick-toggle_minor" href="#">@Html.Label("Minor Update Details")</a>
    <div id="slickbox_minor">@Html.TextAreaFor(model => model.MinorUpdateDetails)<br />
    @Html.LabelFor(model => model.MinorUpdate)<br />
    @Html.TextAreaFor(model => model.MinorUpdate)<br /></div></div>
    <div><a id="slick-toggle_privs" href="#">Manage Privileges</a>
    <div id="slickbox_privs">@Html.LabelFor(model => model.Topic.AllowUpdatePrivsUser)<br />
    @Html.TextBoxFor(model => model.ListAllowEditUser)<br />
    @Html.LabelFor(model => model.Topic.AllowUpdatePrivsRole)<br />
    @Html.TextBoxFor(model => model.ListAllowEditRole)<br />
    @Html.LabelFor(model => model.Topic.DenyReadPrivsUser)<br />
    @Html.TextBoxFor(model => model.ListDenyReadUser)<br />
    @Html.LabelFor(model => model.Topic.DenyReadPrivsRole)<br />
    @Html.TextBoxFor(model => model.ListDenyReadRole)<br /></div></div>
    @Html.HiddenFor(model => model.PagePath)
    @Html.HiddenFor(model => model.TopicName)
    @Html.HiddenFor(model => model.Topic.Version)
    @Html.Hidden("User", (string)ViewBag.User)
}
@section Scripts {
    <script type="text/javascript" >
        $(document).ready(function () {
            $("#btnPreview").click(function (e) {
                $("#frmEditTopic").attr("target", "_blank");
                return true;
            });
            $("#btnNewVersion").click(function (e) {
                $("#frmEditTopic").attr("target", "_self");
                return true;
            });
            $("#btnMinorUpdate").click(function (e) {
                if ($('#MinorUpdate').val()) {
                    $("#frmEditTopic").attr("target", "_self");
                    return true;
                }
                else {
                    $('#ErrorMsgDiv').text('Minor Update must not be null');
                    $('#ErrorMsgDiv').show();
                    return false;
                }
            });
            $('#slickbox_minor').hide();
            $('#slick-toggle_minor').click(function () {
                $('#slickbox_minor').toggle(400);
                return false;
            });
            $('#ErrorMsgDiv').hide();
            $('#slickbox_privs').hide();
            $('#slick-toggle_privs').click(function () {
                $('#slickbox_privs').toggle(400);
                return false;
            });
            $('#wikiMarkupGuide').hide();
            $('#displayMarkupGuide').click(function () {
                if ($('#wikiMarkupGuide').is(':visible')) {
                    $('#wikiMarkupGuide').toggle(200);
                    $('#wikiMarkupGuide').hide();
                    $('.editBody').width('948px');
                }
                else {
                    $('wikiMarkupGuide').toggle(200);
                    $('#wikiMarkupGuide').show();
                    $('.editBody').width('55%');
                }
            });
        });
    </script>
}